package edu.wtbu.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import edu.wtbu.dao.ScheduleDao;
import edu.wtbu.pojo.Result;

/**
 * Servlet implementation class DetailServlet
 */
@WebServlet("/DetailServlet")
public class DetailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DetailServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter printWriter=response.getWriter();
		
		String scheduleid="";
		
		try {
			scheduleid=request.getParameter("scheduleid");
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		ArrayList<HashMap<String, Object>> listsch=ScheduleDao.finschticvk(scheduleid);
		
		if(listsch==null||listsch.size()==0)
		{
			return;
		}
		
		try {
			int airid=Integer.parseInt(listsch.get(0).get("AircraftId").toString());
			ArrayList<HashMap<String, Object>> listtick=ScheduleDao.listtick(scheduleid);
			ArrayList<HashMap<String, Object>> seat=ScheduleDao.seat(scheduleid);
			ArrayList<HashMap<String, Object>> seatlout=ScheduleDao.seatlout(airid);
			HashMap<String, Object> map=new HashMap<String, Object>();
			map.put("listsch", listsch);
			map.put("listtick", listtick);
			map.put("seat", seat);
			map.put("seatlout", seatlout);
			ArrayList<HashMap<String, Object>> allArrayList=new ArrayList<HashMap<String,Object>>();
			allArrayList.add(map);
			Result rr=new Result("success",null,allArrayList);
			String mString=JSON.toJSONString(rr);
			printWriter.append(mString);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
